//
//  UIFont+Ext.m
//  WDPubLib
//
//  Created by wujianrong on 16/4/11.
//  Copyright © 2016年 wanda. All rights reserved.
//

#import "UIFont+wdice.h"
#import <objc/runtime.h>


@implementation UIFont(wdice)

static char* _icesizeWidthKey = "icesizeWidth";
static char* _icesizeHeightKey = "icesizeHeightKey";

-(void)setIceFontSize:(CGSize)fontSize
{
    objc_setAssociatedObject(self, _icesizeWidthKey, [NSNumber numberWithDouble:fontSize.width], OBJC_ASSOCIATION_RETAIN);
    objc_setAssociatedObject(self, _icesizeHeightKey, [NSNumber numberWithDouble:fontSize.height], OBJC_ASSOCIATION_RETAIN);
}

-(CGSize)iceFontSize
{
    NSNumber* sizeWidth = objc_getAssociatedObject(self, _icesizeWidthKey);
    NSNumber* sizeHeight = objc_getAssociatedObject(self, _icesizeHeightKey);
    
    CGSize tempSize;
    tempSize.width = [sizeWidth doubleValue];
    tempSize.height = [sizeHeight doubleValue];
    return tempSize;
}



+(UIFont*)iceFontWithFontName:(NSString*)fontName displayStr:(NSString*)string fontSize:(CGFloat)size
{
    UIFont * titleFont = nil;
    NSString* _tempName = nil;
    if (fontName == nil) {
        _tempName = @"Helvetica";
    }
    else
    {
        _tempName = fontName;
    }
    
    if (size < 0.001) {
        size = 17.0f;
    }
    titleFont = [UIFont fontWithName:_tempName size:size];
    CGSize titleSize;
    
    if (string == nil) {
        titleSize.height = 0;
        titleSize.width = 0;
    }
    else
    {
        titleSize = [string sizeWithAttributes: @{NSFontAttributeName: titleFont}];
    }
    
    titleFont.iceFontSize = titleSize;
    
    return titleFont;
}
@end
